package com.qidianit.task.controller;

import com.qidianit.task.pojo.Project;
import com.qidianit.task.service.ProjectService;
import com.qidianit.task.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author gfdycxy
 * @Company cxy
 * @Description
 * @Time 2024/9/5 18:37
 */
@RestController
@RequestMapping("/project")
@CrossOrigin
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    @GetMapping("/list")
    public QdResult list(Project project, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit) {
        return projectService.queryByPage(project, page, limit);
    }

    @PostMapping("/insert")
    public QdResult insert(@RequestBody Project project) {
        return projectService.insertNewProject(project);
    }

    @GetMapping("/selectByProjectId")
    public QdResult selectByProjectId(String projectId) {
//        System.out.println("前端传来的projectId为"+projectId);
        return projectService.selectByProjectId(projectId);
    }

    @PutMapping("/update")
    public QdResult update(@RequestBody Project project) {
        return projectService.updateById(project);
    }

    @GetMapping("/get")
    public QdResult get(String projectId) {
        return projectService.queryById(projectId);
    }
    //删除将状态改为99
    @DeleteMapping("/delete")
    public QdResult delete(String projectId) {
        return projectService.deleteById(projectId);
    }
    //归档将状态改为3
    @PutMapping("/archive")
    public QdResult archive(String projectId){
        return projectService.archiveById(projectId);
    }
    @PutMapping("/releases")
    public QdResult releases(String [] projectId){
        return projectService.releases(projectId);
    }
    @PutMapping("/archives")
    public QdResult archives(String [] projectId){
        return projectService.archives(projectId);
    }
    @DeleteMapping("/deletes")
    public QdResult deletes(String [] projectId){
        return projectService.deletes(projectId);
    }
    @GetMapping("/listDeletes")
    public QdResult listDeletes(Project project, @RequestParam(defaultValue = "1")int page,@RequestParam(defaultValue = "10")int limit){
        return projectService.queryDeletes(project,page,limit);
    }
    @PutMapping("/reReleases")
    public QdResult reReleases(String [] projectId){
        return projectService.reReleases(projectId);
    }
}